
*Settings
clear all
cap log close
*Change this to your system name
local user "awcassidy1"
set more off, permanently
cd "C:\Users\awcassidy1\Dropbox\jmp_new\cleaned_data"


use "C:\Users\awcassidy1\Dropbox\jmp_new\cleaned_data/data_with_observability_indices.dta", clear




********************************************************************************
*Baseline: observability groups
********************************************************************************
*standard values
local clustvar "mlsid"
local clustvarword "Home"
local fevars "i.saleyear i.lsaleyear i.yearbuiltcat"
local fe_to_absorb="saleyear lsaleyear yearbuiltcat"
local controls "yearbuiltaudit conditionedsqft"
local baselinevars "parsimonious_less parsimonious_more_fuel parsimonious_more_other"
local filename "main"
local depvar "pricediff"
local not_extracted="duct_type  rsavg  eeravg  sizeavg    negsysageavg ah_type notwinrec  notraddr"

local parsimonious_less_vars "negleakavg atticrvalue ductravg     "
local parsimonious_more_vars_fuel "fftype whftype "
local parsimonious_more_vars_other "ah_location progtherm twosystems"


********************************************************************************
*VAR DEFINITIONS AND LABELS
********************************************************************************
gen pre_above_med_ee=above_median_ee_all_mean*pre
gen post_above_med_ee= above_median_ee_all_mean*post
la var pre_above_med_ee "Above Med EE $\times$ Pre-sample"
la var post_above_med_ee "Above Med EE $\times$ Post"
la var above_median_ee_all_mean "Above Med EE"
la var above_median_less "Above Med Less"

gen pre_above_med_less=above_median_less*pre
gen post_above_med_less= above_median_less*post
la var pre_above_med_less "Above Med Less $\times$ Pre-sample"
la var post_above_med_less "Above Med Less $\times$ Post"

gen pre_Less_st = Less_st*pre
gen post_Less_st = Less_st*post
la var pre_Less_st "Less $\times$ Pre"
la var post_Less_st "Less $\times$ Post"

gen pre_More_Fuel_st = More_Fuel_st*pre
gen post_More_Fuel_st = More_Fuel_st*post
la var pre_More_Fuel_st "More-Fuel $\times$ Pre"
la var post_More_Fuel_st "More-Fuel $\times$ Post"

gen pre_More_Other_st = More_Other_st*pre
gen post_More_Other_st = More_Other_st*post
la var pre_More_Other_st "More-Other $\times$ Pre"
la var post_More_Other_st "More-Other $\times$ Post"

				
********************************************************************************
*More robustness: robust to using just homes built before 1999?
********************************************************************************


eststo clear


********************************************************************************
*Robustness of Less Observable to Variety of Controls (table A3)
********************************************************************************
eststo: reghdfe pricediff Less_st yearbuiltaudit conditionedsqft  ///
	 pool ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{No Fuel Switchers}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{Yes}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"

*add not extracted.

eststo: reghdfe pricediff Less_st `not_extracted' yearbuiltaudit conditionedsqft ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{No Fuel Switchers}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{Yes}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{Yes}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"

*add wh tank type controls

eststo: reghdfe pricediff Less_st `not_extracted' yearbuiltaudit conditionedsqft wh_tanktype ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{No Fuel Switchers}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{Yes}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{Yes}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{Yes}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"


*Controls for sqft, beds, baths, pool

eststo: reghdfe pricediff Less_st num_beds_total num_baths_total conditionedsqft  ///
	 pool yearbuiltaudit `not_extracted' wh_tanktype ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{No Fuel Switchers}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{Yes}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{Yes}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{Yes}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{Yes}"

local keepvars Less_st 

esttab using "C:\Users\awcassidy1\Dropbox\jmp_new/tables/less_only_robustness_controls.tex", replace fragment ///
		keep(`keepvars') order(`keepvars') ///
		 label booktabs nomtitles noobs se(4) b(4) ///
		scalars( ///
				"k \textbf{Controls:}" ///
					"control_yblt_sqft Yr Blt \& Sq Ft" ///
						"control_not_extracted Not Extracted" ///
						"control_wh_tanktype WH Tank Type" ///
						"control_bedsbathspool Beds, Baths, Pool" ///
					"n \hline \vspace{\adjust}" ///
				"r2all R-squared" ///
				 "N Observations"  ///
				) ///
				sfmt( 0 0 0 0 0 0 %9.3fc %9.0fc  ) star(* 0.10 ** 0.05 *** 0.01)

********************************************************************************
*Additional fixed effects (Table A5)
********************************************************************************
eststo clear

*year built FE
eststo: reghdfe pricediff Less_st ///
	 	, ///
		vce(cl mlsid) absorb(yearbuiltaudit saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"
estadd local clust_levl = "\multicolumn{1}{c}{Home}"

estadd local elem_fe = "\multicolumn{1}{c}{No}"
estadd local yb_fe =  "\multicolumn{1}{c}{Yes}"
estadd local zip_fe =  "\multicolumn{1}{c}{No}"



*zip FE, cluster at Home level

eststo: reghdfe pricediff Less_st ///
	 	, ///
		vce(cl mlsid) absorb(yearbuiltcat zip saleyear lsaleyear )	

estadd scalar r2all = e(r2)

estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"
estadd local clust_levl = "\multicolumn{1}{c}{Home}"

estadd local elem_fe = "\multicolumn{1}{c}{No}"
estadd local yb_fe =  "\multicolumn{1}{c}{No}"
estadd local zip_fe =  "\multicolumn{1}{c}{Yes}"

*zip FE, cluster at zip code level
eststo: reghdfe pricediff Less_st ///
	 	, ///
		vce(cl zip) absorb(yearbuiltcat zip saleyear lsaleyear )	

estadd scalar r2all = e(r2)

estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"
estadd local clust_levl = "\multicolumn{1}{c}{Zip}"

estadd local elem_fe = "\multicolumn{1}{c}{No}"
estadd local yb_fe =  "\multicolumn{1}{c}{No}"
estadd local zip_fe =  "\multicolumn{1}{c}{Yes}"


*elementary school FE
eststo: reghdfe pricediff Less_st ///
	 	, ///
		vce(cl mlsid) absorb(yearbuiltcat elementary saleyear lsaleyear )	

estadd scalar r2all = e(r2)

estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"
estadd local clust_levl = "\multicolumn{1}{c}{Home}"

estadd local elem_fe = "\multicolumn{1}{c}{Yes}"
estadd local yb_fe =  "\multicolumn{1}{c}{No}"
estadd local zip_fe =  "\multicolumn{1}{c}{No}"

*cluster elementary school, with elementary school FE
eststo: reghdfe pricediff Less_st ///
	 	, ///
		vce(cl elementary) absorb(yearbuiltcat elementary saleyear lsaleyear )	

estadd scalar r2all = e(r2)

estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"
estadd local clust_levl = "\multicolumn{1}{c}{Elementary}"

estadd local elem_fe = "\multicolumn{1}{c}{Yes}"
estadd local yb_fe =  "\multicolumn{1}{c}{No}"
estadd local zip_fe =  "\multicolumn{1}{c}{No}"


esttab using "C:\Users\awcassidy1\Dropbox\jmp_new/tables/less_only_robustness_fe_cl.tex", replace fragment ///
		keep(`keepvars') order(`keepvars') ///
		 label booktabs nomtitles noobs se(4) b(4) ///
		scalars( ///
				"k \textbf{FE:}" ///
					"yb_fe Yr Blt" ///
						"zip_fe Zip Code" ///
						"elem_fe Elementary" ///
					"n \hline \vspace{\adjust}" ///
				"r2all R-squared" ///
				"clust_levl Cluster Level" ///
				"N_clust Clusters" "N Observations"  ///
				) ///
				sfmt( 0 0 0 0 0  %9.3fc %9.0fc  %9.0fc ) star(* 0.10 ** 0.05 *** 0.01)


********************************************************************************
*sample and dep var (Table A4)
********************************************************************************
eststo clear

*built before 1999
eststo: reghdfe pricediff Less_st  ///
	if yearbuiltcat==0 ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{Built before 1999}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"


*exclude repeat sales within 1 year.
eststo: reghdfe pricediff Less_st  ///
	if saled-lsaled>365 ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{No Flipped}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"


*exclude sale price<5 percentile or above 95th percentile
sum closeprice1, detail
local ub=r(p95)
local lb=r(p5)

eststo: reghdfe pricediff Less_st  ///
	if closeprice1>`lb' & closeprice1<`ub' ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{No Price Outliers}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"

*log price diff
gen logpricediff=ln(price*10000)-ln((l.price)*10000) if !missing(pricediff)

eststo: reghdfe logpricediff Less_st ///
	 	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ ln(P)}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"
estadd local control_bedsbathspool =  "\multicolumn{1}{c}{No}"


local keepvars Less_st 
		 
esttab using "C:\Users\awcassidy1\Dropbox\jmp_new/tables/less_only_robustness_sample_depvar.tex", replace fragment ///
		keep(`keepvars') order(`keepvars') ///
		 label booktabs nomtitles noobs se(4) b(4) ///
		scalars( ///
					"sample Sample" ///
					"dep_var Dep Var" ///
				"r2all R-squared" ///
				 "N Observations"  ///
				) ///
				sfmt( 0 0 %9.3fc %9.0fc ) star(* 0.10 ** 0.05 *** 0.01)